package api

import (
	"github.com/gin-gonic/gin"
	"gorm.io/gorm"
	"net/http"
	"zg3wee3/model/mysql"
	"zg3wee3/router"
)

func Login(c *gin.Context) {
	var App router.User
	if err := c.ShouldBind(&App); err != nil {
		c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
		return
	}
	stu := mysql.User{
		Username: App.Username,
		PassWord: App.PassWord,
	}
	err := stu.Create()
	if err != nil {
		c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
		return
	}
	c.JSON(http.StatusOK, gin.H{"msg": "登录成功"})
}
func Like(c *gin.Context) {
	var App router.Like
	if err := c.ShouldBind(&App); err != nil {
		c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
		return
	}
	sta := mysql.Like{
		Model: gorm.Model{ID: uint(App.Id)},
	}
	err := sta.List()
	if err != nil {
		c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
		return
	}
	c.JSON(http.StatusBadRequest, gin.H{"msg": "查询成功", "sta": sta})
}
func Add(c *gin.Context) {
	var App router.Add
	if err := c.ShouldBind(&App); err != nil {
		c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
		return
	}
	stu := mysql.Like{
		Sx: App.Sx,
		Yw: App.Yw,
		Sw: App.Sw,
		Dl: App.Dl,
	}
	err := stu.Add()
	if err != nil {
		c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
		return
	}
	c.JSON(http.StatusBadRequest, gin.H{"msg": "添加成功"})
}
func Care(c *gin.Context) {
	var App router.Create
	if err := c.ShouldBind(&App); err != nil {
		c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
		return
	}
	stu := mysql.Add{
		Sx: App.Sx,
		Yw: App.Yw,
		Sw: App.Sw,
		Dl: App.Dl,
		Dz: App.Dz,
		Pl: App.Pl,
	}
	err := stu.Create1()
	if err != nil {
		c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
		return
	}
	c.JSON(http.StatusBadRequest, gin.H{"msg": "添加成功"})
}
